package cn.hejiang.order.controller;

import cn.hejiang.basic.util.AjaxResult;
import cn.hejiang.basic.util.LoginContext;
import cn.hejiang.basic.util.PageList;
import cn.hejiang.order.domain.AdoptOrder;
import cn.hejiang.order.query.AdoptOrderQuery;
import cn.hejiang.order.service.IAdoptOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/adoptOrder")
public class AdoptOrderController {

    @Autowired
    private IAdoptOrderService adoptOrderService;

    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody Map<String, Object> params, HttpServletRequest request) {
        try {
            String payData = adoptOrderService.submit(params, LoginContext.currentLoginInfo(request));
            System.out.println(payData);
            return AjaxResult.me().setResultObj(payData);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("下单失败！" + e.getMessage());
        }
    }

    // 平台员工 + 平台店铺
    @PostMapping("/admin")
    public PageList<AdoptOrder> admin(@RequestBody AdoptOrderQuery query, HttpServletRequest request) {
        return adoptOrderService.admin(query, LoginContext.currentLoginInfo(request));
    }

    // 主站用户
    @PostMapping("/user")
    public PageList<AdoptOrder> user(@RequestBody AdoptOrderQuery query, HttpServletRequest request) {
        return adoptOrderService.user(query, LoginContext.currentLoginInfo(request));
    }

    @GetMapping("/{id}")
    public AdoptOrder getInfo(@PathVariable("id") Long id) {
        return adoptOrderService.queryById(id);
    }
}
